#include <opencv2/opencv.hpp>
#include <iostream>

using namespace std;

int main(int argc, char** argv) {
    // 10-15
    cv::Mat matWithLines(512, 512, CV_8UC1, cv::Scalar(0)), dst;
    cv::RNG rng = cv::theRNG();
    for(int i = 0; i < 9; i++) {
        cv::line(
            matWithLines, 
            cv::Point(rng.uniform(0,512),rng.uniform(0,512)), 
            cv::Point(rng.uniform(0,512),rng.uniform(0,512)), 
            cv::Scalar(255),1
        );
    }
    // 45 degree line
    line(matWithLines, cv::Point(0,512), cv::Point(512,0), cv::Scalar(255), 1);
    matWithLines.convertTo(matWithLines, CV_32FC1, 1.0/255);

    // detect
    cv::Mat kernel(3,3,CV_32FC1, cv::Scalar(0));
    kernel.at<float>(0,0) = 0;
    kernel.at<float>(0,1) = 0;
    kernel.at<float>(0,2) = 1.0/3;
    kernel.at<float>(1,0) = 0;
    kernel.at<float>(1,1) = 1.0/3;
    kernel.at<float>(1,2) = 0;
    kernel.at<float>(2,0) = 1.0/3;
    kernel.at<float>(2,1) = 0;
    kernel.at<float>(2,2) = 0;  
    cv::filter2D(matWithLines, dst, CV_32FC1, kernel);
    cv::threshold(dst, dst, 0.99, 1, cv::THRESH_BINARY);

    cv::imshow("src", matWithLines);
    cv::imshow("detect", dst);

    cv::waitKey(0);
    return 0;
}